﻿@model Windvoice.Blog.Article
@using Windvoice.Blog
@using Windvoice.Authorize

@{
    ViewBag.Title = String.Format("{0} -- Blogs", Model.Title);
    Layout = "~/Views/Shared/_Layout.cshtml";
}

@section headSection{
    <link href="@Url.Content("~/Content/editor/plugin/code/prettify.css")" rel="stylesheet" type="text/css" />
    <script src="@Url.Content("~/Content/editor/xheditor.js")" type="text/javascript"></script>
    <script src="@Url.Content("~/Content/editor/plugin/code/prettify.js")" type="text/javascript"></script>
    <script type="text/javascript">
        $(function () {
            $('#comment-content').xheditor({ height: 150, width: 520, tools: 'Cut,Copy,Paste,Pastetext,' });
            $('#commet-submit').click(function () {
                if ($('#comment-content').val().replace(/(^[\\s]*)|([\\s]*$)/g, '') == '') {
                    alert('童鞋，输点什么再提交哦～');
                    return false;
                }
            });

            if (!$.browser.msie) {
                var pre = $('.prettyprint');
                pre.each(function () {
                    var code = $(this).html().replace(/\n/ig, '</li><li>');
                    code = '<div class="codetitle">代码段</div><ol><li>' + code + '</li></ol>';
                    $(this).html(code);
                });
                pre.find('div.codetitle').click(function () {
                    $(this).next().slideToggle('fast');
                });
                prettyPrint();
            }

        });
    </script>
}

<div class="body-left">
    <div class="artical-list">
        <div class="article-block blog-@(Enum.Parse(typeof(WindvoiceWeatherCondition), Model.Weather.ToString()).ToString().ToLower())">
            <div class="head">
                <div class="date">
                    <div class="upper">@Model.CreateTime.ToString("yyyy-MM")</div>
                    <div class="lower">@Model.CreateTime.ToString("dd")</div>
                </div>
                <div class="title">
                    <h3>
                        <a href="/blog/@Model.UniqueKey">@Model.Title</a>
                    </h3>
                        <p>
                            by @Model.Author 
                            at @Model.CreateTime.ToString("HH:mm:ss") 
                            in <a href="/blogs/@Category.Find(Model.CategoryID).UniqueKey">@Category.Find(Model.CategoryID).Name</a>
                        </p>
                </div>
            </div>
            <div class="content">
                @Html.Raw(Model.Content)
            </div>
            <div class="tail">
                <div class="left">
                    Temperature:@Model.Hits℃ | 
                    Comments:@Comment.GetCommentCount(Model.ID)
                </div>
                <div class="right">
                    <iframe allowTransparency="true" class="weibo-share" frameborder="0" scrolling="no" src="http://hits.sinajs.cn/A1/weiboshare.html?url=@(Request.Url)&type=3&ralateUid=104312&title=@(Server.UrlEncode(Model.Title))&rnd=@(new Random().Next())&width=16&height=16"></iframe>
                </div>
            </div>
        </div>
    </div>

    <div class="neighbours">
        @{
            var PreviousBlog = ((Article[])ViewBag.Neighbours)[0];
            var NextBlog = ((Article[])ViewBag.Neighbours)[1];
        }
        <div class="previous">
            <span>Prev: </span>
            @if (PreviousBlog == null)
            {
                @:没有啦！
            }
            else
            {
                <a href="/blog/@PreviousBlog.UniqueKey">@PreviousBlog.Title</a> 
            }
        </div>
        <div class="next">
            <span>Next: </span>
            @if (NextBlog == null)
            {
                @:没有啦！
            }
            else
            { 
                <a href="/blog/@NextBlog.UniqueKey">@NextBlog.Title</a>
            }
        </div>
    </div>

    <div class="related">
        <div class="title">Related Blogs</div>
        <ul class="list">
            @foreach (var article in (Article[])ViewBag.RelatedBlogs)
            {
                <li><a href="/blog/@article.UniqueKey" title="@article.Title">@article.Title</a></li>
            }
        </ul>
    </div>

    <div class="comment">
        <ul class="comment-list">
            @{ int i = 1;}
            @foreach (var comment in (Comment[])ViewBag.Comments)
            {
                var CommentUser = Windvoice.Authorize.User.Find(comment.UserID);
                <li class="comment-item" id="@(String.Format("comment{0}", comment.ID))">
                    <div class="portrait">
                        <img src="@CommentUser.PortraitUrl" alt="@CommentUser.DisplayName"/>
                        <p>@CommentUser.DisplayName</p>
                    </div>
                    <div class="content">
                        <div>
                            <p class="stair left">
                            @switch (i)
                            {
                                case 1:
                                    @:沙发！
                                    break;
                                case 2:
                                    @:板凳
                                    break;
                                case 3:
                                    @:地板
                                    break;
                                default:
                                    @String.Format("地板{0}层", i-1)
                               break;

                            }
                            </p>
                            <p class="time right">@comment.CreateTime.ToString("yyyy-MM-dd HH:mm:ss")</p>
                            <div class="clear"></div>
                        </div>
                        <p class="words">@comment.Content</p>
                        @if (!String.IsNullOrEmpty(comment.Reply))
                        {
                            <p class="reply">
                                Windvoice replied on @comment.ReplyTime.ToString("yyyy-MM-dd HH:mm:ss"):<br/>
                                @comment.Reply
                            </p>
                        }
                    </div>            
                    <div class="clear"></div>
                </li> 
                        i++;
            }
        </ul>
        <div class="commentform">
            @if (Session["user"] == null)
            {
                <form action="/user/connect?returnurl=@Server.UrlEncode(Request.Url.OriginalString)" method="post" id="form1">
                    <input type="submit" value="" style="border:0;background:url(/Content/images/connect-to-sina.png);height:24px;width:126px;cursor:pointer" />
                    <input type="hidden" value="1" name="provider" />
                </form>
                <form action="/user/connect?returnurl=@Server.UrlEncode(Request.Url.OriginalString)" method="post" id="form2">
                    <input type="submit" value="" style="border:0;background:url(/Content/images/connect-to-qq.png);height:24px;width:126px;cursor:pointer" />
                    <input type="hidden" value="2" name="provider" />
                </form>
            }
            else
            {
                var user = (User)Session["user"];
                
                <p class="welcome">欢迎您，@user.DisplayName，来了一趟，留点什么吧：<br/><br/></p>
                <form action="" method="post">
                    <div class="commentform-portrait">
                        <img src="@user.PortraitUrl"  alt="@user.DisplayName"/>
                    </div>
                    <div class="commentform-words">
                        <textarea name="comment" id="comment-content"></textarea>
                    </div>
                    <div class="clear"></div>
                    <div class="commentform-button">                    
                        <input type="submit" value="提 交" id="commet-submit" />
                    </div>
                </form>
            }
        </div>
    </div>

</div>


@Html.Partial("_PartialRight")
<div class="clear"></div>